'   Copyright (C) 2011  Jan-Willem de Bruyn

'   This program is free software: you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation, either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>. 

 Public Class Form1
    Dim num As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox2.Text = "get num" Then
            ListBox1.Items.Add(num)
            TextBox2.Text = ""
            Exit Sub
        End If
        Dim middle() As String = TextBox2.Text.Split(" ")
        Dim i As Integer
        Dim stri As String = ""
        For Each Str As String In middle
            Dim i2 As Integer = Str.Length
            If i2 > i Then
                i = i2
                stri = Str
            End If
        Next
        If Not num > i Then
            num = i
        End If
        Dim i3 As Integer = 0
        If ListBox1.Items.Contains(stri) Then
            Exit Sub
        ElseIf ListBox1.Items.Count = 0 Then
            ListBox1.Items.Add(stri)
            TextBox2.Text = ""
            Exit Sub
        Else
            ListBox1.Items.Add(stri)
            TextBox2.Text = ""
        End If

    End Sub
    Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If e.KeyChar = vbCr Then
            Button1_Click(sender, e)
        End If
    End Sub
End Class
